
{***********************************************************}
{                                                           }
{      Informix Data Access Components                      }
{                                                           }
{      Informix Interface                                   }
{                                                           }
{      Copyright (c) 2001-2008 Luxena Software Company      }
{      http://www.luxena.com                                }
{      e-mail: support@luxena.com                           }
{                                                           }
{***********************************************************}

unit IfxIntf;

{$I lx.inc}

interface

uses
  IfxSqlIApi, IfxSqlHdr, IfxSqlProto, IfxSrvInfo;

const
  IfxLibraryName = 'isqlt09a.dll';

var
  ifx_getenv: Tifx_getenv;
  ifx_putenv: Tifx_putenv;

  fnsqlcode: Tfnsqlcode;
  fnsqlstate: Tfnsqlstate;
  fnsqlca: Tfnsqlca;

  sqlstart: Tsqlstart;
  sqldetach: Tsqldetach;
  sqlexit: Tsqlexit;
  
  sqli_connect_open: Tsqli_connect_open;
  sqli_connect_set: Tsqli_connect_set;
  sqli_connect_close: Tsqli_connect_close;
  ifx_getcur_conn_name: Tifx_getcur_conn_name;

  ifx_srvinfo: Tifx_srvinfo_proc;
  ifx_isius: Tifx_isius;

  sqgetdbs: Tsqgetdbs;
  sqli_db_open: Tsqli_db_open;
  sqli_db_close: Tsqli_db_close;

  sqlbreakcallback: Tsqlbreakcallback;
  sqldone: Tsqldone;
  sqlbreak: Tsqlbreak;

  sqli_trans_begin: Tsqli_trans_begin;
  sqli_trans_begin2: Tsqli_trans_begin2;
  sqli_trans_commit: Tsqli_trans_commit;
  sqli_trans_rollback: Tsqli_trans_rollback;

  sqli_prep: Tsqli_prep;
  sqli_desc_alloc: Tsqli_desc_alloc;
  sqli_desc_dealloc: Tsqli_desc_dealloc;
  sqli_desc_get: Tsqli_desc_get;
  sqli_curs_free: Tsqli_curs_free;
  sqli_exec: Tsqli_exec;
  sqli_exec_immed: Tsqli_exec_immed;
  sqli_stmt: Tsqli_stmt;
  sqli_slct: Tsqli_slct;
  sqli_curs_locate: Tsqli_curs_locate;
  sqli_curs_decl_dynm: Tsqli_curs_decl_dynm;
  sqli_describe_stmt: Tsqli_describe_stmt;
  sqli_curs_open: Tsqli_curs_open;
  sqli_curs_close: Tsqli_curs_close;
  sqli_curs_fetch: Tsqli_curs_fetch;
  sqli_mt_hostbind: Tsqli_mt_hostbind;
  sqli_diag_get: Tsqli_diag_get;

  bycmpr: Tbycmpr;
  bycopy: Tbycopy;
  byfill: Tbyfill;
  byleng: Tbyleng;
  
  decadd: Tdecadd;
  deccmp: Tdeccmp;
  deccopy: Tdeccopy;
  deccvasc: Tdeccvasc;
  deccvdbl: Tdeccvdbl;
  deccvint: Tdeccvint;
  deccvlong: Tdeccvlong;
  decdiv: Tdecdiv;
  dececvt: Tdececvt;
  decfcvt: Tdecfcvt;
  decmul: Tdecmul;
  decround: Tdecround;
  decsub: Tdecsub;
  dectoasc: Tdectoasc;
  dectodbl: Tdectodbl;
  dectoint: Tdectoint;
  dectolong: Tdectolong;
  dectrunc: Tdectrunc;

  dtaddinv: Tdtaddinv;
  dtcurrent: Tdtcurrent;
  dtcvasc: Tdtcvasc;
  dtcvfmtasc: Tdtcvfmtasc;
  dtextend: Tdtextend;
  dtsub: Tdtsub;
  dtsubinv: Tdtsubinv;
  dttoasc: Tdttoasc;
  dttofmtasc: Tdttofmtasc;

  incvasc: Tincvasc;
  incvfmtasc: Tincvfmtasc;
  intoasc: Tintoasc;
  intofmtasc: Tintofmtasc;
  invdivdbl: Tinvdivdbl;
  invdivinv: Tinvdivinv;
  invextend: Tinvextend;
  invmuldbl: Tinvmuldbl;
  
  ifx_getserial8: Tifx_getserial8;
  ifx_int8add: Tifx_int8add;
  ifx_int8cmp: Tifx_int8cmp;
  ifx_int8copy: Tifx_int8copy;
  ifx_int8cvasc: Tifx_int8cvasc;
  ifx_int8cvdbl: Tifx_int8cvdbl;
  ifx_int8cvdec: Tifx_int8cvdec;
  ifx_int8cvflt: Tifx_int8cvflt;
  ifx_int8cvint: Tifx_int8cvint;
  ifx_int8cvlong: Tifx_int8cvlong;
  ifx_int8div: Tifx_int8div;
  ifx_int8mul: Tifx_int8mul;
  ifx_int8sub: Tifx_int8sub;
  ifx_int8toasc: Tifx_int8toasc;
  ifx_int8todbl: Tifx_int8todbl;
  ifx_int8todec: Tifx_int8todec;
  ifx_int8toflt: Tifx_int8toflt;
  ifx_int8toint: Tifx_int8toint;
  ifx_int8tolong: Tifx_int8tolong;

  ifx_var_alloc: Tifx_var_alloc;
  ifx_var_dealloc: Tifx_var_dealloc;
  ifx_var_freevar: TIfx_var_freevar;
  ifx_var_flag: Tifx_var_flag;
  ifx_var_init: Tifx_var_init;
  ifx_var_getdata: Tifx_var_getdata;
  ifx_var_getlen: Tifx_var_getlen;
  ifx_var_isnull: Tifx_var_isnull;
  ifx_var_setdata: Tifx_var_setdata;
  ifx_var_setlen: Tifx_var_setlen;
  ifx_var_setnull: Tifx_var_setnull;

  ifx_lo_alter: Tifx_lo_alter;
  ifx_lo_close: Tifx_lo_close;
  ifx_lo_col_info: Tifx_lo_col_info;
  ifx_lo_copy_to_file: Tifx_lo_copy_to_file;
  ifx_lo_copy_to_lo: Tifx_lo_copy_to_lo;
  ifx_lo_create: Tifx_lo_create;
  ifx_lo_def_create_spec: Tifx_lo_def_create_spec;
  ifx_lo_filename: Tifx_lo_filename;
  ifx_lo_from_buffer: Tifx_lo_from_buffer;
  ifx_lo_open: Tifx_lo_open;
  ifx_lo_read: Tifx_lo_read;
  ifx_lo_readwithseek: Tifx_lo_readwithseek;
  ifx_lo_release: Tifx_lo_release;
  ifx_lo_seek: Tifx_lo_seek;
  ifx_lo_spec_free: Tifx_lo_spec_free;
  ifx_lo_specget_estbytes: Tifx_lo_specget_estbytes;
  ifx_lo_specget_extsz: Tifx_lo_specget_extsz;
  ifx_lo_specget_flags: Tifx_lo_specget_flags;
  ifx_lo_specget_maxbytes: Tifx_lo_specget_maxbytes;
  ifx_lo_specget_sbspace: Tifx_lo_specget_sbspace;
  ifx_lo_specset_estbytes: Tifx_lo_specset_estbytes;
  ifx_lo_specset_extsz: Tifx_lo_specset_extsz;
  ifx_lo_specset_flags: Tifx_lo_specset_flags;
  ifx_lo_specset_maxbytes: Tifx_lo_specset_maxbytes;
  ifx_lo_specset_sbspace: Tifx_lo_specset_sbspace;
  ifx_lo_stat: Tifx_lo_stat;
  ifx_lo_stat_atime: Tifx_lo_stat_atime;
  ifx_lo_stat_cspec: Tifx_lo_stat_cspec;
  ifx_lo_stat_ctime: Tifx_lo_stat_ctime;
  ifx_lo_stat_free: Tifx_lo_stat_free;
  ifx_lo_stat_mtime_sec: Tifx_lo_stat_mtime_sec;
  ifx_lo_stat_refcnt: Tifx_lo_stat_refcnt;
  ifx_lo_stat_size: Tifx_lo_stat_size;
  ifx_lo_tell: Tifx_lo_tell;
  ifx_lo_to_buffer: Tifx_lo_to_buffer;
  ifx_lo_truncate: Tifx_lo_truncate;
  ifx_lo_write: Tifx_lo_write;
  ifx_lo_writewithseek: Tifx_lo_writewithseek;
  ifx_lo_lock: Tifx_lo_lock;
  ifx_lo_unlock: Tifx_lo_unlock;

  rdatestr: Trdatestr;
  rdayofweek: Trdayofweek;
  rdefmtdate: Trdefmtdate;
  rdownshift: Trdownshift;
  rfmtdate: Trfmtdate;
  rfmtdec: Trfmtdec;
  rfmtdouble: Trfmtdouble;
  rfmtlong: Trfmtlong;
  rgetlmsg: Trgetlmsg;
  rgetmsg: Trgetmsg;
  risnull: Trisnull;
  rjulmdy: Trjulmdy;
  rleapyear: Trleapyear;
  rmdyjul: Trmdyjul;
  rsetnull: Trsetnull;
  rstod: Trstod;
  rstoi: Trstoi;
  rstol: Trstol;
  rstrdate: Trstrdate;
  rtoday: Trtoday;
  rtypalign: Trtypalign;
  rtypmsize: Trtypmsize;
  rtypname: Trtypname;
  rtypwidth: Trtypwidth;
  rupshift: Trupshift;

  ldchar: Tldchar;
  stcat: Tstcat;
  stchar: Tstchar;
  stcmpr: Tstcmpr;
  stcopy: Tstcopy;
  stleng: Tstleng;

  InetLogin: Tfninetlogin;
  SqlFreeMem: TSqlFreeMem;


implementation

uses
  Windows, SysUtils, IfxConsts;


var
  IfxLibraryHandle: THandle;

procedure LoadIfxLibrary;

  procedure LoadError(const Msg: string);
  begin
    MessageBox(0, PChar(Msg), PChar(SLibraryErrorCaption), MB_OK or MB_ICONERROR);
    Halt;
  end;

  function GetProcAddr(const ProcName: string): Pointer;
  begin
    Result := GetProcAddress(IfxLibraryHandle, PChar(ProcName));
    if not Assigned(Result) then
      LoadError(Format(SLibraryProcMissing, [ProcName, IfxLibraryName]));
  end;

begin
  IfxLibraryHandle := LoadLibrary(PChar(IfxLibraryName));
  if IfxLibraryHandle = 0 then
    LoadError(Format(SLibraryErrorMessage, [IfxLibraryName]));

  ifx_getenv := GetProcAddr('ifx_getenv');
  ifx_putenv := GetProcAddr('ifx_putenv');

  fnsqlcode := GetProcAddr('fnsqlcode');
  fnsqlstate := GetProcAddr('fnsqlstate');
  fnsqlca := GetProcAddr('fnsqlca');

  sqlstart := GetProcAddr('sqlstart');
  sqldetach := GetProcAddr('sqldetach');
  sqlexit := GetProcAddr('sqlexit');

  sqli_connect_open := GetProcAddr('sqli_connect_open');
  sqli_connect_set := GetProcAddr('sqli_connect_set');
  sqli_connect_close := GetProcAddr('sqli_connect_close');
  ifx_getcur_conn_name := GetProcAddr('ifx_getcur_conn_name');

  ifx_srvinfo := GetProcAddr('ifx_srvinfo');
  ifx_isius := GetProcAddr('ifx_isius');

  sqgetdbs := GetProcAddr('sqgetdbs');
  sqli_db_open := GetProcAddr('sqli_db_open');
  sqli_db_close := GetProcAddr('sqli_db_close');

  sqlbreakcallback := GetProcAddr('sqlbreakcallback');
  sqldone := GetProcAddr('sqldone');
  sqlbreak := GetProcAddr('sqlbreak');

  sqli_trans_begin := GetProcAddr('sqli_trans_begin');
  sqli_trans_begin2 := GetProcAddr('sqli_trans_begin2');
  sqli_trans_commit := GetProcAddr('sqli_trans_commit');
  sqli_trans_rollback := GetProcAddr('sqli_trans_rollback');

  sqli_prep := GetProcAddr('sqli_prep');
  sqli_desc_alloc := GetProcAddr('sqli_desc_alloc');
  sqli_desc_dealloc := GetProcAddr('sqli_desc_dealloc');
  sqli_desc_get := GetProcAddr('sqli_desc_get');
  sqli_curs_free := GetProcAddr('sqli_curs_free');
  sqli_exec := GetProcAddr('sqli_exec');
  sqli_exec_immed := GetProcAddr('sqli_exec_immed');
  sqli_stmt := GetProcAddr('sqli_stmt');
  sqli_slct := GetProcAddr('sqli_slct');
  sqli_curs_locate := GetProcAddr('sqli_curs_locate');
  sqli_curs_decl_dynm := GetProcAddr('sqli_curs_decl_dynm');
  sqli_describe_stmt := GetProcAddr('sqli_describe_stmt');
  sqli_curs_open := GetProcAddr('sqli_curs_open');
  sqli_curs_close := GetProcAddr('sqli_curs_close');
  sqli_curs_fetch := GetProcAddr('sqli_curs_fetch');
  sqli_mt_hostbind := GetProcAddr('sqli_mt_hostbind');
  sqli_diag_get := GetProcAddr('sqli_diag_get');

  bycmpr := GetProcAddr('bycmpr');
  bycopy := GetProcAddr('bycopy');
  byfill := GetProcAddr('byfill');
  byleng := GetProcAddr('byleng');

  decadd := GetProcAddr('decadd');
  deccmp := GetProcAddr('deccmp');
  deccopy := GetProcAddr('deccopy');
  deccvasc := GetProcAddr('deccvasc');
  deccvdbl := GetProcAddr('deccvdbl');
  deccvint := GetProcAddr('deccvint');
  deccvlong := GetProcAddr('deccvlong');
  decdiv := GetProcAddr('decdiv');
  dececvt := GetProcAddr('dececvt');
  decfcvt := GetProcAddr('decfcvt');
  decmul := GetProcAddr('decmul');
  decround := GetProcAddr('decround');
  decsub := GetProcAddr('decsub');
  dectoasc := GetProcAddr('dectoasc');
  dectodbl := GetProcAddr('dectodbl');
  dectoint := GetProcAddr('dectoint');
  dectolong := GetProcAddr('dectolong');
  dectrunc := GetProcAddr('dectrunc');

  dtaddinv := GetProcAddr('dtaddinv');
  dtcurrent := GetProcAddr('dtcurrent');
  dtcvasc := GetProcAddr('dtcvasc');
  dtcvfmtasc := GetProcAddr('dtcvfmtasc');
  dtextend := GetProcAddr('dtextend');                
  dtsub := GetProcAddr('dtsub');
  dtsubinv := GetProcAddr('dtsubinv');
  dttoasc := GetProcAddr('dttoasc');
  dttofmtasc := GetProcAddr('dttofmtasc');

  incvasc := GetProcAddr('incvasc');
  incvfmtasc := GetProcAddr('incvfmtasc');
  intoasc := GetProcAddr('intoasc');
  intofmtasc := GetProcAddr('intofmtasc');
  invdivdbl := GetProcAddr('invdivdbl');
  invdivinv := GetProcAddr('invdivinv');
  invextend := GetProcAddr('invextend');
  invmuldbl := GetProcAddr('invmuldbl');

  ifx_getserial8 := GetProcAddr('ifx_getserial8');
  ifx_int8add := GetProcAddr('ifx_int8add');
  ifx_int8cmp := GetProcAddr('ifx_int8cmp');
  ifx_int8copy := GetProcAddr('ifx_int8copy');
  ifx_int8cvasc := GetProcAddr('ifx_int8cvasc');
  ifx_int8cvdbl := GetProcAddr('ifx_int8cvdbl');
  ifx_int8cvdec := GetProcAddr('ifx_int8cvdec');
  ifx_int8cvflt := GetProcAddr('ifx_int8cvflt');
  ifx_int8cvint := GetProcAddr('ifx_int8cvint');
  ifx_int8cvlong := GetProcAddr('ifx_int8cvlong');
  ifx_int8div := GetProcAddr('ifx_int8div');
  ifx_int8mul := GetProcAddr('ifx_int8mul');
  ifx_int8sub := GetProcAddr('ifx_int8sub');
  ifx_int8toasc := GetProcAddr('ifx_int8toasc');
  ifx_int8todbl := GetProcAddr('ifx_int8todbl');
  ifx_int8todec := GetProcAddr('ifx_int8todec');
  ifx_int8toflt := GetProcAddr('ifx_int8toflt');
  ifx_int8toint := GetProcAddr('ifx_int8toint');
  ifx_int8tolong := GetProcAddr('ifx_int8tolong');

  ifx_var_alloc := GetProcAddr('ifx_var_alloc');
  ifx_var_dealloc := GetProcAddr('ifx_var_dealloc');
  { on Win32 platform ifx_var_freevar is present only in 2.80TC1 and later }
  ifx_var_freevar := GetProcAddress(IfxLibraryHandle, 'ifx_var_freevar');
  ifx_var_flag := GetProcAddr('ifx_var_flag');
  ifx_var_init := GetProcAddr('ifx_var_init');
  ifx_var_getdata := GetProcAddr('ifx_var_getdata');
  ifx_var_getlen := GetProcAddr('ifx_var_getlen');
  ifx_var_isnull := GetProcAddr('ifx_var_isnull');
  ifx_var_setdata := GetProcAddr('ifx_var_setdata');
  ifx_var_setlen := GetProcAddr('ifx_var_setlen');
  ifx_var_setnull := GetProcAddr('ifx_var_setnull');
    
  ifx_lo_alter := GetProcAddr('ifx_lo_alter');
  ifx_lo_close := GetProcAddr('ifx_lo_close');
  ifx_lo_col_info := GetProcAddr('ifx_lo_col_info');
  ifx_lo_copy_to_file := GetProcAddr('ifx_lo_copy_to_file');
  ifx_lo_copy_to_lo := GetProcAddr('ifx_lo_copy_to_lo');
  ifx_lo_create := GetProcAddr('ifx_lo_create');
  ifx_lo_def_create_spec := GetProcAddr('ifx_lo_def_create_spec');
  ifx_lo_filename := GetProcAddr('ifx_lo_filename');
  ifx_lo_from_buffer := GetProcAddr('ifx_lo_from_buffer');
  ifx_lo_open := GetProcAddr('ifx_lo_open');
  ifx_lo_read := GetProcAddr('ifx_lo_read');
  ifx_lo_readwithseek := GetProcAddr('ifx_lo_readwithseek');
  ifx_lo_release := GetProcAddr('ifx_lo_release');
  ifx_lo_seek := GetProcAddr('ifx_lo_seek');
  ifx_lo_spec_free := GetProcAddr('ifx_lo_spec_free');
  ifx_lo_specget_estbytes := GetProcAddr('ifx_lo_specget_estbytes');
  ifx_lo_specget_extsz := GetProcAddr('ifx_lo_specget_extsz');
  ifx_lo_specget_flags := GetProcAddr('ifx_lo_specget_flags');
  ifx_lo_specget_maxbytes := GetProcAddr('ifx_lo_specget_maxbytes');
  ifx_lo_specget_sbspace := GetProcAddr('ifx_lo_specget_sbspace');
  ifx_lo_specset_estbytes := GetProcAddr('ifx_lo_specset_estbytes');
  ifx_lo_specset_extsz := GetProcAddr('ifx_lo_specset_extsz');
  ifx_lo_specset_flags := GetProcAddr('ifx_lo_specset_flags');
  ifx_lo_specset_maxbytes := GetProcAddr('ifx_lo_specset_maxbytes');
  ifx_lo_specset_sbspace := GetProcAddr('ifx_lo_specset_sbspace');
  ifx_lo_stat := GetProcAddr('ifx_lo_stat');
  ifx_lo_stat_atime := GetProcAddr('ifx_lo_stat_atime');
  ifx_lo_stat_cspec := GetProcAddr('ifx_lo_stat_cspec');
  ifx_lo_stat_ctime := GetProcAddr('ifx_lo_stat_ctime');
  ifx_lo_stat_free := GetProcAddr('ifx_lo_stat_free');
  ifx_lo_stat_mtime_sec := GetProcAddr('ifx_lo_stat_mtime_sec');
  ifx_lo_stat_refcnt := GetProcAddr('ifx_lo_stat_refcnt');
  ifx_lo_stat_size := GetProcAddr('ifx_lo_stat_size');
  ifx_lo_tell := GetProcAddr('ifx_lo_tell');
  ifx_lo_to_buffer := GetProcAddr('ifx_lo_to_buffer');
  ifx_lo_truncate := GetProcAddr('ifx_lo_truncate');
  ifx_lo_write := GetProcAddr('ifx_lo_write');
  ifx_lo_writewithseek := GetProcAddr('ifx_lo_writewithseek');
  ifx_lo_lock := GetProcAddr('ifx_lo_lock');
  ifx_lo_unlock := GetProcAddr('ifx_lo_unlock');

  rdatestr := GetProcAddr('rdatestr');
  rdayofweek := GetProcAddr('rdayofweek');
  rdefmtdate := GetProcAddr('rdefmtdate');
  rdownshift := GetProcAddr('rdownshift');
  rfmtdate := GetProcAddr('rfmtdate');
  rfmtdec := GetProcAddr('rfmtdec');
  rfmtdouble := GetProcAddr('rfmtdouble');
  rfmtlong := GetProcAddr('rfmtlong');
  rgetlmsg := GetProcAddr('rgetlmsg');
  rgetmsg := GetProcAddr('rgetmsg');
  risnull := GetProcAddr('risnull');
  rjulmdy := GetProcAddr('rjulmdy');
  rleapyear := GetProcAddr('rleapyear');
  rmdyjul := GetProcAddr('rmdyjul');
  rsetnull := GetProcAddr('rsetnull');
  rstod := GetProcAddr('rstod');
  rstoi := GetProcAddr('rstoi');
  rstol := GetProcAddr('rstol');
  rstrdate := GetProcAddr('rstrdate');
  rtoday := GetProcAddr('rtoday');
  rtypalign := GetProcAddr('rtypalign');
  rtypmsize := GetProcAddr('rtypmsize');
  rtypname := GetProcAddr('rtypname');
  rtypwidth := GetProcAddr('rtypwidth');
  rupshift := GetProcAddr('rupshift');

  ldchar := GetProcAddr('ldchar');
  stcat := GetProcAddr('stcat');
  stchar := GetProcAddr('stchar');
  stcmpr := GetProcAddr('stcmpr');
  stcopy := GetProcAddr('stcopy');
  stleng := GetProcAddr('stleng');

  InetLogin := GetProcAddr('fninetlogin');
  SqlFreeMem := GetProcAddr('SqlFreeMem');
end;

procedure FreeIfxLibrary;
begin
  if IfxLibraryHandle <> 0 then
  begin
    FreeLibrary(IfxLibraryHandle);
    IfxLibraryHandle := 0;
  end;
end;


initialization
  LoadIfxLibrary;

finalization
  FreeIfxLibrary;

end.